package com.example.controller.handle;

import com.alibaba.dubbo.config.annotation.Reference;
import com.example.common.api.user.service.RegisterService;
import com.example.common.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Auther: wyj
 * @Description:注册功能的handler
 */
@Controller
public class RegisterController {
    @Reference(version = "1.0.0")
    private RegisterService registerService;

    @GetMapping("/registerServlet.do")
    public String register(HttpServletRequest request, HttpServletResponse response) throws IOException {
        //从表单中获取数据
        String username = request.getParameter("username");
        String name = request.getParameter("name");
        String password = request.getParameter("password");

        //将username,phone,password以及一些初始化数据封装到User对象中
        User user = new User();
        user.setUsername(username);
        user.setName(name);
        user.setPassword(password);
        user.setArticlenum(0);
        user.setAttentionnum(0);
        user.setFansnum(0);
        user.setWordsnum(0);

        //调用service层方法
        registerService.register(user);

        //跳转页面
        return "index";
    }
}